<?php

class Photo {
	var $idphoto;
	var $name;
	var $src;
	var $title;
	var $album;
	var $fecha;
	
	function Photo()
	{
		
	}
	
	function setPhoto($id, $nombre, $fuente, $titulo, $album, $fecha)
	{
		$this->idphoto=$id;
		$this->name=$nombre;
		$this->src=$fuente;
		$this->title=$titulo;
		$this->album=$album;
		$this->fecha=$fecha;
	}

	public static function getPhotos($object, $idalbum)
	{
		$sql="SELECT * FROM photos WHERE idalbum=".$idalbum;
		$rs=DataBase::ExecuteQuery($sql, "ARRAY");
		
		foreach ($rs as $key => $value)
		{
			$photo= new Photo();
			$photo->setPhoto($value['idphoto'], $value['name'], $value['src'], $value['title'], $value['idalbum'], $value['fecha']);
			array_push($object, $photo);
		}
		return $object;
	}
	
	function getOnePhoto($idphoto)
	{
		$sql="SELECT * FROM photos WHERE idphoto=".$idphoto;
		$rs=DataBase::ExecuteQuery($sql, "ARRAY");
		
		$this->setPhoto($ph['idphoto'], $ph['name'], $ph['src'], $ph['title'], $ph['idalbum'], $ph['fecha']);
			
	}
	
	function getOnePhotoRandom($idalbum)
	{
		$sql="SELECT * FROM photos WHERE idalbum=".$idalbum;
		$rs=DataBase::ExecuteQuery($sql, "ARRAY");
		
		$ph=$rs[array_rand($rs,1)];
	
		$this->setPhoto($ph['idphoto'], $ph['name'], $ph['src'], $ph['title'], $ph['idalbum'], $ph['fecha']);
				
		
	}
	
}

?>